#pragma once
#include "bullet.h"
#include "Animation.h"
extern IMAGE img_pea;
extern Atlas atlas_pea_break;
class PeaBullet : public Bullet
{
public:
	PeaBullet()
	{
		size = { 64,64 };
		damage = 10;
		animation_break.set_atlas(&atlas_pea_break);
		animation_break.set_interval(100);
		animation_break.set_loop(false);
		animation_break.set_callback([&]() {can_remove = true; });
	}
	~PeaBullet() = default;

	void set_attack_CD(int CD)
	{
		attack_CD = CD;
	}
	int get_attack_CD()
	{
		return attack_CD;
	}
	bool check_collision(const Vector2& position, const Vector2& size)
	{
		return this->position.x + this->size.x / 2 >= position.x
			&& this->position.x + this->size.x / 2 <= position.x + size.x / 2
			&& this->position.y + this->size.y / 2 >= position.y
			&& this->position.y + this->size.y / 2 <= position.y + size.y;
	}
	void on_collide()
	{
		Bullet::on_collide();

		switch (rand() % 3)
		{
		case 0:
			mciSendString(L"play pea_break_1 from 0", NULL , 0, NULL);
			break;
		case 1:
			mciSendString(L"play pea_break_2 from 0", NULL, 0, NULL);
			break;
		case 2:
			mciSendString(L"play pea_break_3 from 0", NULL, 0, NULL);
			break;
		}
	}
	void on_draw(const Camera& camera) override
	{
		if (valid)
			putimagePNG(camera, (int)position.x, (int)position.y, &img_pea);
		else
			animation_break.on_draw(camera, (int)position.x, (int)position.y);
		Bullet::on_draw(camera);
	}
	void on_update(int delta)
	{
		
		if (valid)
			position += speed * (float)delta;
		else
			animation_break.on_update(delta);
		if (check_if_exceeds_screen())
			can_remove = true;
	}
	
private:
	Animation animation_break;

};